{-# OPTIONS -Wall #-}


module CpsMon.Lam
  (

    VarId
  , Expr(..)
  , Constant(..)

  , ppExpr

  ) where

import Text.PrettyExprHPJ                   -- package: pretty-expr-hpj
import Text.PrettyExprHPJ.Ocaml

import Text.PrettyPrint.HughesPJ            -- package: pretty


type VarId = String

data Expr = Constant Constant
          | Var VarId
          | Lam VarId Expr
          | App Expr Expr 
  deriving (Eq,Show)

data Constant = Int Int
              | PrintC
  deriving (Eq,Show)


ppExpr :: Expr -> Doc 
ppExpr = unparse . exprDoc

exprDoc :: Expr -> DocE
exprDoc (Constant c)    = Atom $ ppConstant c
exprDoc (Var v)         = literal v
exprDoc (Lam v e)       = Atom $ char '\\' <> text v <+> text "->" <+> ppExpr e
exprDoc (App e1 e2)     = funAppB1 (exprDoc e1) (exprDoc e2)

ppConstant :: Constant -> Doc
ppConstant (Int i)      = int i
ppConstant (PrintC)     = text "print_c"
